#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Solution
{
private:
    // 70. Climbing Stairs
    int climbStairs(int n)
    {
        vector<int> arr = {1, 2};
        for (int i = 2; i < n; i++)
        {
            arr.push_back(arr[i - 1] + arr[i - 2]);
        }
        return arr[n - 1];
    }

    // Helper for Pascal's Triangle
    vector<int> addRows(const vector<int> &arr)
    {
        vector<int> ans = {1};
        for (int i = 0; i + 1 < arr.size(); i++)
        {
            ans.push_back(arr[i] + arr[i + 1]);
        }
        ans.push_back(1);
        return ans;
    }

    // 118. Pascal's Triangle
    vector<vector<int>> generate(int numRows)
    {
        vector<vector<int>> res = {{1}};
        for (int i = 2; i <= numRows; i++)
        {
            res.push_back(addRows(res.back()));
        }
        return res;
    }

    // 119. Pascal's Triangle II
    vector<int> getRow(int rowIndex)
    {
        vector<int> row = {1};
        for (int i = 1; i <= rowIndex; i++)
        {
            row = addRows(row);
        }
        return row;
    }

    // 121. Best Time to Buy and Sell Stock
    int maxProfit(vector<int> &prices)
    {
        int maxVal = prices.back();
        int res = 0;
        for (int i = prices.size() - 2; i >= 0; i--)
        {
            res = max(res, maxVal - prices[i]);
            maxVal = max(maxVal, prices[i]);
        }
        return res;
    }

    // 338. Counting Bits
    vector<int> countBits(int n)
    {
        vector<int> dp(n + 1);
        dp[0] = 0;
        if (n == 0)
            return dp;
        dp[1] = 1;
        for (int i = 2; i <= n; i++)
        {
            dp[i] = dp[i / 2] + (i % 2);
        }
        return dp;
    }

    // 392. Is Subsequence
    bool isSubsequence(string s, string t)
    {
        int s_i = 0, n = s.size();
        for (int t_i = 0; t_i < t.size(); t_i++)
        {
            if (s[s_i] == t[t_i])
            {
                s_i++;
            }
            if (s_i == n)
                break;
        }
        return s_i == n;
    }
};
